package com.syqc.monitor.popup

import android.animation.ObjectAnimator
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.LinearLayout
import android.widget.PopupWindow
import com.syqc.monitor.databinding.PopupStopBinding

/**
 *@author  hfjs
 *@time   2025/3/4 17:30
 *@desc
 */
class StopPopup(context: Context) : PopupWindow() {
    private val binding = PopupStopBinding.inflate(LayoutInflater.from(context))

    init {
        contentView = binding.root
        isClippingEnabled = false
        setBackgroundDrawable(ColorDrawable(-0x56000000)) //设置背景
        isOutsideTouchable = true //点击外面窗口消失
        width = LinearLayout.LayoutParams.MATCH_PARENT //设置SelectPicPopupWindow弹出窗体的宽
        height = LinearLayout.LayoutParams.MATCH_PARENT //设置SelectPicPopupWindow弹出窗体的高


        // 创建一个向左的平移动画
        val moveAnim: ObjectAnimator =
            ObjectAnimator.ofFloat(binding.ivScroll, View.TRANSLATION_X, 0f, -400f)
        moveAnim.setDuration(2000) // 设置动画持续时间为 2000 毫秒
        moveAnim.repeatCount = ObjectAnimator.INFINITE // 设置动画无限循环
        moveAnim.interpolator = LinearInterpolator() // 设置动画插值器为线性插值器，使动画匀速进行

        moveAnim.start() // 启动动画

        binding.root.setOnClickListener {
            dismiss()
            moveAnim.cancel()
        }
    }
}